Imports System.Drawing.Drawing2D

Public Class UcnBrushPopupControl
    'represents PopupContainerControl for setting a MindFusion.Drawing.LinearGradientBrush

#Region "Properties"
#Region "Public properties"
    'LinearGradientBrush - result of this "control"
    Public ReadOnly Property Result() As MindFusion.Drawing.LinearGradientBrush
        Get
            Return New MindFusion.Drawing.LinearGradientBrush(ceBeginColor.Color, ceEndColor.Color, edtAngle.Value)
        End Get
    End Property
#End Region
#End Region
#Region "Constructors"
    Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Init(MFLinearGradientBrushCreator(Color.Black, Color.Black, 100))
    End Sub

    Sub New(ByVal IoBrush As MindFusion.Drawing.LinearGradientBrush)

        ' This call is required by the Windows Form Designer.
        InitializeComponent()
        ' Add any initialization after the InitializeComponent() call.

        Init(IoBrush)
    End Sub
#End Region
#Region "Events handler"
    'repainting of preview 
    Private Sub PopupContainerControl_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PopupContainerControl.Paint
        PaintPreview()
    End Sub
    'repainting of preview 
    Private Sub edtAngle_EditValueChanging(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.ChangingEventArgs) Handles edtAngle.EditValueChanging
        PaintPreview()
    End Sub
    'repainting of preview 
    Private Sub edtAngle_EditValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles edtAngle.EditValueChanged
        PaintPreview()
    End Sub
#End Region
#Region "Subs"
    'initialization of controls
    Public Sub Init(ByVal IoBrush As MindFusion.Drawing.LinearGradientBrush)
        If IoBrush IsNot Nothing Then
            ceBeginColor.Color = IoBrush.LinearColors(0)
            ceEndColor.Color = IoBrush.LinearColors(1)
            edtAngle.Value = IoBrush.Angle
        Else
            Debug.Print("UcnBrushPopupControl.Init prazdny objekt")
            ceBeginColor.Color = Color.Black
            ceEndColor.Color = Color.Black
            edtAngle.Value = 100
        End If
    End Sub
    'painting of preview
    Private Sub PaintPreview()
        Dim LoHwnd As IntPtr = PopupContainerControl.Handle
        Dim LoGraphics As System.Drawing.Graphics = Graphics.FromHwnd(LoHwnd)

        Dim LoRectangleF As RectangleF = SDRectangleFVirginCreator(200, 20, 90, 107)
        LoGraphics.FillRectangle(New LinearGradientBrush(LoRectangleF, ceBeginColor.Color, ceEndColor.Color, edtAngle.Value), LoRectangleF)
    End Sub
#End Region

End Class
